const Koa = require("koa");
const app = new Koa();

// 注册中间件
app.use((ctx, next) => {
  console.log("中间件1");
  ctx.msg = "hello koa01";
  next();
  console.log("中间件1");

  ctx.body = ctx.msg; // 返回结果 hello koa01 hello koa02 hello koa03
});

app.use((ctx, next) => {
  console.log("中间件2");
  ctx.msg += " hello koa02";
  next();
  console.log("中间件2");
});

app.use((ctx, next) => {
  console.log("中间件3");
  ctx.msg += " hello koa03";
});

app.listen(8000, () => {
  console.log("服务器启动成功~");
});
